import ByteArray = require("bytearray-node");
type int = number;
//class ProtocolHead

/**
 * 协议头,总共20字节
 * CDE!(4)
 * protocol(1)=1
 * encoding(1)=1
 * reserve1(1)=0
 * reserve2(1)=0
 * messageSize(4)=0
 * verifyResult(4)=0
 * messageType(1)=0
 * compressionStatus(1)=0
 * encryptStatus(1)=0
 * encryptAddLength(1)=0
 */
export class ProtocolHead {
  public __read(arg1: ByteArray): void {
    this.magic1 = arg1.readByte();
    this.magic2 = arg1.readByte();
    this.magic3 = arg1.readByte();
    this.magic4 = arg1.readByte();
    this.protocol = arg1.readByte();
    this.encoding = arg1.readByte();
    this.reserve1 = arg1.readByte();
    this.reserve2 = arg1.readByte();
    this.messageSize = arg1.readInt();
    this.verifyResult = arg1.readInt();
    this.messageType = arg1.readByte();
    this.compressionStatus = arg1.readByte();
    this.encryptStatus = arg1.readByte();
    this.encryptAddLength = arg1.readByte();
    return;
  }

  public __write(arg1: ByteArray): void {
    arg1.writeByte(this.magic1);
    arg1.writeByte(this.magic2);
    arg1.writeByte(this.magic3);
    arg1.writeByte(this.magic4);
    arg1.writeByte(this.protocol);
    arg1.writeByte(this.encoding);
    arg1.writeByte(this.reserve1);
    arg1.writeByte(this.reserve2);
    arg1.writeInt(this.messageSize);
    arg1.writeInt(this.verifyResult);
    arg1.writeByte(this.messageType);
    arg1.writeByte(this.compressionStatus);
    arg1.writeByte(this.encryptStatus);
    arg1.writeByte(this.encryptAddLength);
    return;
  }

  public static /* const */ CDF_PROTOCOL_INT_VERSION: int = 1;

  public static /* const */ CDF_ENCODING_INT_VERSION: int = 1;

  public static /* const */ CDF_PROTOCOL_HEAD_SIZE: int = 24;

  public static /* const */ CDF_PROTOCOL_MAX_SIZE: int = 1024 * 500;

  public /* var */ magic1: int = String("C").charCodeAt(0);

  public /* var */ magic2: int = String("D").charCodeAt(0);

  public /* var */ magic3: int = String("E").charCodeAt(0);

  public /* var */ magic4: int = String("!").charCodeAt(0);

  public /* var */ protocol: int = ProtocolHead.CDF_PROTOCOL_INT_VERSION;

  public /* var */ encoding: int = ProtocolHead.CDF_ENCODING_INT_VERSION;

  public /* var */ reserve1: int = 0;

  public /* var */ reserve2: int = 0;

  public /* var */ messageSize: int = 0;

  public /* var */ verifyResult: int = 0;

  public /* var */ messageType: int = 0;

  public /* var */ compressionStatus: int = 0;

  public /* var */ encryptStatus: int = 0;

  public /* var */ encryptAddLength: int = 0;
}
